package com.example.mapboot.controller;

import com.example.mapboot.dto.Results;
import com.example.mapboot.dto.covid.CovidDTO;
import com.example.mapboot.dto.place.PlaceDTO;
import com.example.mapboot.utils.BaiduApiUtils;
import com.example.mapboot.utils.CovidUtils;
import com.example.mapboot.utils.Response;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/baidu")
public class BaiduMapController {

    @RequestMapping("/getCoordinate")
    public Response getCoordinate(@RequestParam String address) {
        List<Results> coordinateList = BaiduApiUtils.getCoordinateList(address);
        if (coordinateList.size() != 0) {
            return Response.success(coordinateList);
        }
        return Response.error("查询地址暂无结果!");
    }

    @RequestMapping("/getWeather")
    public  Response getWeather(String provice,String city,String area,String name){
        String weather = BaiduApiUtils.getWeather(provice, city, area,name);
        return Response.success(weather);
    }

    @RequestMapping("/getCovid")
    public Response getCovid(){
        CovidDTO covid = CovidUtils.getCovid();
        if(covid.getCode()==10000){
            return  Response.success(covid.getData());
        }else{
            return Response.error("暂无数据");
        }
    }

    @RequestMapping("/getPlace")
    public Response getPlace(String province,String city,String area){
        String tempArea = "";
        if(province!=null){
            tempArea = province;
        }

        if(city!=null){
            tempArea = city;
        }

        if(area!=null){
            tempArea = area;
        }

        if("".equalsIgnoreCase(tempArea)){
            return Response.error("暂无数据");
        }


        PlaceDTO tag = BaiduApiUtils.getTag("景点", "景点", tempArea);
        if(tag.getStatus()==0){
            return  Response.success(tag.getResults());
        }else{
            return Response.error("暂无数据");
        }
    }
}
